package com.itheima.cartweb.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.itheima.pojo.ShopCart;
import com.itheima.service.CartService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class CartController {

    @Reference
    private CartService cartService;

    @GetMapping("/cart")
    public String cart(){
        return "cart";
    }

    @GetMapping("/list")
    @ResponseBody
    public PageInfo<ShopCart> findByPage(@RequestParam(defaultValue = "1") int pageNum,
                                         @RequestParam(defaultValue = "5")int pageSize){
        return cartService.findByPage(pageNum,pageSize);
    }

    @PutMapping("/selectAll")
    @ResponseBody
    public int selectAll(int index){
        return cartService.selectAll(index);
    }

    @PutMapping("/selectOne")
    @ResponseBody
    public int selectOne(int index,int id){
        return cartService.selectOne(index,id);
    }

    @PostMapping("save")
    @ResponseBody
    public int save(@RequestBody ShopCart shopCart){
        return cartService.save(shopCart);
    }

    @DeleteMapping("delete")
    @ResponseBody
    public int delete(int id){
        return cartService.delete(id);
    }
}
